<!--
 * @Author: YuA
 * @Date: 2021-07-31 17:24:21
 * @LastEditTime: 2021-08-17 23:41:14
 * @FilePath: \index\src\components\common\Tabbar\TabBarItem.vue
-->
<template>
  <div class="nav_item" @click="itemClick">
    <div class="tab-bar-item" :class="isColor">
      <slot name="item-icon" :style="bgc"></slot>
    </div>
    <div>
      <slot name="item-text"></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: "TabBarItem",
  props: {
    path: String,
    color: {
      type: String,
      default: "#fff"
    },
    bgc: {
      type: String,
      default: "#daa8a8"
    }
  },
  data() {
    return {};
  },
  computed: {
    isFlag() {
      return this.$route.path.indexOf(this.path) !== -1;
    },
    isColor() {
      return this.isFlag ? { color: this.color } : {};
    },
    isBgc() {
      return this.isFlag ? { backgroundColor: this.bgc } : {};
    }
  },
  methods: {
    itemClick() {
      this.$router.replace(this.path).catch(err => err);
    }
  }
};
</script>

<style lang="scss" scoped>
.nav_item {
  display: flex;
  flex-direction: column;

  flex: 1;
  width: 50px;
  height: 55px;
  text-align: center;
  line-height: 1.5;
}
span {
  display: block;
  font-size: 24px;
}

.tab-bar-item {
  display: flex;
  justify-content: center;
}

.color {
  span {
    color: #fff;
    background-color: #daa8a8;
  }
}
</style>
